home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / Antialias.asm next >
Assembly Source File  |  1993-08-31  |  35KB  |  1,842 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| This file contains the optimized assembly-language versions of the low-level
  3. //| graphics routines used by HyperCuber.  See HyperCuber Graphics.c for the c
  4. //| versions of these algorithms
  5. //|________________________________________________________________________________
  6.  
  7.  
  8. #include <asm.h>
  9. #include <FixMath.h>
  10.  
  11. #if 0
  12.  
  13. Fract intensity_table[16] = {    0x40000000, 0x3EF8D2E5, 0x3BEFE0CE, 0x370C77DE,
  14.                                 0x30965F52, 0x29086BDF, 0x214BD33D, 0x1A03A323,
  15.                                 0x1371971C, 0x0DBFD2E9, 0x09086BDF, 0x055831F0,
  16.                                 0x02AF5C0E, 0x0100BE01, 0x002EA30B, 0x00000000   };
  17.  
  18. #endif
  19.                 //  Gamma-corrected table
  20. Fract intensity_table[16] = {    0x40000000, 0x3F7BE113, 0x3DEF698D, 0x3B5B190E,
  21.                                 0x37C38384, 0x333EDBB1, 0x2E298B52, 0x28CDA516,
  22.                                 0x2346A93B, 0x1DA9FF4C, 0x180B37DF, 0x127E9B84,
  23.                                 0x0D1BD877, 0x0802F777, 0x036A209F, 0x00000000   };
  24.  
  25.  
  26. void DrawAntialiasedLineO1asm(long x1, long y1, long x2, long y2, RGBColor *color);
  27. void DrawAntialiasedLineO1asm(long x1, long y1, long x2, long y2, RGBColor *color)
  28. {
  29.  
  30.     long             dx, dy;
  31.     register long    d;
  32.     register long    line_width;
  33.     register long    two_dx_invDenom;
  34.     long            invDenom;
  35.     register long    count;
  36.     long             incrE, incrNE, two_v_dx;
  37.     RGBColor         old_color;
  38.     RGBColor         new_color;
  39.     PixMapHandle     pixmap;
  40.     register unsigned char    *pix;
  41.  
  42.     unsigned char    color_table[16];
  43.     RGBColor        table_color;
  44.     long            i, debug;
  45.     Fract            fract_intensity;
  46.     Fixed            intensity;
  47.     
  48.     pixmap = ((CGrafPtr) thePort)->portPixMap;        //  Find address of starting pixel
  49.     line_width = (*pixmap)->rowBytes & 0x7FFF;
  50.     pix = (unsigned char *) (*pixmap)->baseAddr -
  51.                             (*pixmap)->bounds.top*line_width -
  52.                             (*pixmap)->bounds.left +
  53.                             line_width*y1 + x1;
  54.  
  55. asm {
  56.  
  57. //==== create table of frequently used colors (used when drawing on black)
  58.  
  59.     move.l    d3, -(SP)                    ; save d3
  60.     
  61.     move.l    #15, count
  62.  
  63. color_loop:
  64.  
  65.     lea        table_color, a1
  66.     
  67.     lea        intensity_table, a0            ; look up the intensity in the table
  68.     move.l    count, d0
  69.     move.l    d0, debug
  70.     move.l    0(a0, d0.w*4), d3
  71.     move.l    d3, debug
  72.  
  73.     move.l    #15, d1                        ; intensity in d3
  74.     asr.l    d1, d3
  75.  
  76.     move.l    d3, debug
  77.  
  78.     move.l    color, a0                    ; multiply red by intensity
  79.     moveq    #0, d0                        
  80.     move.w    0(a0), d0
  81.     muls.l    d3, d0
  82.     moveq    #15, d2
  83.     asr.l    d2, d0
  84.     move.w    d0, 0(a1)
  85.  
  86.     moveq    #0, d0                        ; multiply green by intensity
  87.     move.w    2(a0), d0
  88.     muls.l    d3, d0
  89.     moveq    #15, d2
  90.     asr.l    d2, d0
  91.     move.w    d0, 2(a1)
  92.  
  93.     moveq    #0, d0                        ; multiply blue by intensity
  94.     move.w    4(a0), d0
  95.     muls.l    d3, d0
  96.     moveq    #15, d2
  97.     asr.l    d2, d0
  98.     move.w    d0, 4(a1)
  99.  
  100.     move.l    a1, -(SP)                    ; find index for this color
  101.     _Color2Index
  102.     
  103.     lea        color_table, a0                ; save this index in the table
  104.     move.b    d0, 0(a0, count)
  105.     
  106.     subq    #1, count
  107.     bpl        @color_loop
  108.     
  109.     move.l    (SP)+, d3                    ; restore d3
  110.  
  111. //==== set up to draw line    
  112.     
  113.     move.l    x2, dx                ; dx = x2 - x1
  114.     move.l    x1, d0
  115.     sub.l    d0, dx
  116.     
  117.     move.l    y2, dy                ; dy = y2 - y1
  118.     move.l    y1, d0
  119.     sub.l    d0, dy
  120.     
  121.     move.l    dy, d                ; d = 2*dy - dx
  122.     add.l    d, d
  123.     sub.l    dx, d
  124.     
  125.     move.l    dy, d0                ; incrE = 2*dy
  126.     add.l    d0, d0
  127.     move.l    d0, incrE
  128.     
  129.     move.l    dy, d0                ; incrNE = 2*(dy-dx)
  130.     sub.l    dx, d0
  131.     add.l    d0, d0
  132.     move.l    d0, incrNE
  133.  
  134.     move.l    #0, two_v_dx;        ; two_v_dx = 0
  135.     
  136.     ; the next section computes 1/(2*sqrt(dx*dx + dy*dy) using integer arithmetic
  137.     
  138.     move.l    dx, d0                ; compute dx*dx + dy*dy
  139.     muls.l    d0, d0
  140.     move.l    dy, d1
  141.     muls.l    d1, d1
  142.     add.l    d1, d0
  143.     
  144.     move.l    #12, d1
  145.     asl.l    d1, d0                ; take the square root
  146.     move.l    d0, -(SP)
  147.     _FracSqrt
  148.  
  149.     move.l    (SP), d0            ; find the denominator
  150.     asr.l    #4, d0
  151.     
  152.     move.l    #0x10000, -(SP)        ; do the division
  153.     move.l    d0, -(SP)
  154.     _FracDiv
  155.  
  156.     move.l    (SP), invDenom
  157.     
  158.     move.l    invDenom, two_dx_invDenom    ; two_dx_invDenom = 2*dx*invDenom
  159.     muls.l    dx, two_dx_invDenom
  160.     add.l    two_dx_invDenom, two_dx_invDenom
  161.  
  162.     move.l    dx, count
  163.     
  164.     bra        @move_done
  165.     
  166. xloop:
  167.  
  168.     sub.l    #1, count            ; loop while count > 0
  169.     bmi        @done
  170.  
  171.     tst.l    d
  172.     bge        @move_northeast
  173.  
  174. move_east:
  175.  
  176.     move.l    d, d0                ; two_v_dx = d + dx
  177.     add.l    dx, d0
  178.     move.l    d0, two_v_dx
  179.     
  180.     add.l    incrE, d            ; d = d + incrE
  181.         
  182.     addq    #1, pix                ; x = x + 1
  183.     
  184.     bra        @move_done
  185.     
  186. move_northeast:
  187.  
  188.     move.l    d, d0                ; two_v_dx = d - dx
  189.     sub.l    dx, d0
  190.     move.l    d0, two_v_dx
  191.     
  192.     add.l    incrNE, d            ; d = d + incrE
  193.     
  194.     add.l    line_width, pix        ; y = y + 1
  195.     addq    #1, pix                ; x = x + 1
  196.  
  197. move_done:
  198.  
  199.  
  200. //========== Draw first pixel
  201.     
  202.     moveq    #0, d0                        ; push pixel value
  203.     move.b    (pix), d0
  204.     move.l    d0, -(SP)
  205.     pea        old_color                    ; push address of old_color
  206.     _Index2Color                        ; get previous rgb pixel value
  207.  
  208.     move.l    two_v_dx, d0                ; distance = two_v_dx * invDenom
  209.     muls.l    invDenom, d0
  210.  
  211.     bpl        @positive1                    ; get absolute value of distance
  212.  
  213.     neg.l    d0
  214.  
  215. positive1:
  216.  
  217.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  218.     asr.l    d1, d0
  219.     muls.l    #10, d0
  220.     add.l    #0x8000, d0
  221.     moveq.l    #16, d1
  222.     asr.l    d1, d0
  223.     
  224.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  225.     tst.l    (a0)
  226.     bne        @notzero1
  227.     tst.w    4(a0)
  228.     bne        @notzero1
  229.     
  230.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  231.     move.b    0(a0, d0), d0
  232.     bra        @drawpixel1
  233.  
  234. @notzero1
  235.     
  236.     lea.l    intensity_table, a0            ; look up the intensity in the table
  237.     move.l    0(a0, d0*4), d0
  238.  
  239.     move.l    #15, d1
  240.     asr.l    d1, d0
  241.     move.l    d0, intensity
  242.  
  243.     move.l    color, a0
  244.     lea        new_color, a1
  245.     lea        old_color, a2
  246.     moveq    #0, d1                        ; Find intensities of color components
  247.     move.w    0(a0), d1
  248.     muls.l    d1, d0
  249.     moveq    #15, d2
  250.     asr.l    d2, d0
  251.     add.w    0(a2), d0
  252.     bcc        @red_ok1
  253.     move.w    #0xFFFF, d0
  254. red_ok1:
  255.     move.w    d0, 0(a1)
  256.     
  257.     move.l    intensity, d0
  258.     move.w    2(a0), d1
  259.     muls.l    d1, d0
  260.     moveq    #15, d2
  261.     asr.l    d2, d0
  262.     add.w    2(a2), d0
  263.     bcc        @green_ok1
  264.     move.w    #0xFFFF, d0
  265. green_ok1:
  266.     move.w    d0, 2(a1)
  267.     
  268.     move.l    intensity, d0
  269.     moveq    #0, d1
  270.     move.w    4(a0), d1
  271.     muls.l    d1, d0
  272.     moveq    #15, d2
  273.     asr.l    d2, d0
  274.     add.w    4(a2), d0
  275.     bcc        @blue_ok1
  276.     move.w    #0xFFFF, d0
  277. blue_ok1:
  278.     move.w    d0, 4(a1)
  279.  
  280.     move.l    a1, -(SP)            ; find index for new_color
  281.     _Color2Index
  282.     
  283. drawpixel1:
  284.  
  285.     move.b    d0, (pix)
  286.  
  287.  
  288. //======== Draw the second pixel
  289.  
  290.     add.l    line_width, pix                ; pix += line_width;
  291.  
  292.     moveq    #0, d0                        ; push pixel value
  293.     move.b    (pix), d0
  294.     move.l    d0, -(SP)
  295.     pea        old_color                    ; push address of old_color
  296.     _Index2Color                        ; get previous rgb pixel value
  297.  
  298.     move.l    two_v_dx, d1                ; distance = two_dx_invDenom - two_v_dx * invDenom
  299.     muls.l    invDenom, d1
  300.     move.l    two_dx_invDenom, d0
  301.     sub.l    d1, d0
  302.  
  303.     bpl        @positive2                    ; get absolute value of distance
  304.  
  305.     neg.l    d0
  306.  
  307. positive2:
  308.  
  309.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  310.     asr.l    d1, d0
  311.     muls.l    #10, d0
  312.     add.l    #0x8000, d0
  313.     moveq.l    #16, d1
  314.     asr.l    d1, d0
  315.     
  316.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  317.     tst.l    (a0)
  318.     bne        @notzero2
  319.     tst.w    4(a0)
  320.     bne        @notzero2
  321.     
  322.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  323.     move.b    0(a0, d0.w*1), d0
  324.     bra        @drawpixel2
  325.  
  326. notzero2:
  327.     lea.l    intensity_table, a0            ; look up the intensity in the table
  328.     move.l    0(a0, d0.w*4), d0
  329.  
  330.     move.l    #15, d1
  331.     asr.l    d1, d0
  332.     move.l    d0, intensity
  333.  
  334.     move.l    color, a0
  335.     lea        new_color, a1
  336.     lea        old_color, a2
  337.     moveq    #0, d1                        ; Find intensities of color components
  338.     move.w    0(a0), d1
  339.     muls.l    d1, d0
  340.     moveq    #15, d2
  341.     asr.l    d2, d0
  342.     add.w    0(a2), d0
  343.     bcc        @red_ok2
  344.     move.w    #0xFFFF, d0
  345. red_ok2:
  346.     move.w    d0, 0(a1)
  347.     
  348.     move.l    intensity, d0
  349.     move.w    2(a0), d1
  350.     muls.l    d1, d0
  351.     moveq    #15, d2
  352.     asr.l    d2, d0
  353.     add.w    2(a2), d0
  354.     bcc        @green_ok2
  355.     move.w    #0xFFFF, d0
  356. green_ok2:
  357.     move.w    d0, 2(a1)
  358.     
  359.     move.l    intensity, d0
  360.     moveq    #0, d1
  361.     move.w    4(a0), d1
  362.     muls.l    d1, d0
  363.     moveq    #15, d2
  364.     asr.l    d2, d0
  365.     add.w    4(a2), d0
  366.     bcc        @blue_ok2
  367.     move.w    #0xFFFF, d0
  368. blue_ok2:
  369.     move.w    d0, 4(a1)
  370.  
  371.     move.l    a1, -(SP)            ; find index for new_color
  372.     _Color2Index
  373.     
  374. drawpixel2:
  375.     move.b    d0, (pix)
  376.  
  377.     sub.l    line_width, pix                ; pix -= line_width;
  378.  
  379.  
  380. //======== Draw the third pixel
  381.  
  382.     sub.l    line_width, pix                ; pix -= line_width;
  383.  
  384.     moveq    #0, d0                        ; push pixel value
  385.     move.b    (pix), d0
  386.     move.l    d0, -(SP)
  387.     pea        old_color                    ; push address of old_color
  388.     _Index2Color                        ; get previous rgb pixel value
  389.  
  390.     move.l    two_v_dx, d0                ; distance = two_dx_invDenom + two_v_dx * invDenom
  391.     muls.l    invDenom, d0
  392.     add.l    two_dx_invDenom, d0
  393.  
  394.     bpl        @positive3                    ; get absolute value of distance
  395.  
  396.     neg.l    d0
  397.  
  398. positive3:
  399.  
  400.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  401.     asr.l    d1, d0
  402.     muls.l    #10, d0
  403.     add.l    #0x8000, d0
  404.     moveq.l    #16, d1
  405.     asr.l    d1, d0
  406.     
  407.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  408.     tst.l    (a0)
  409.     bne        @notzero3
  410.     tst.w    4(a0)
  411.     bne        @notzero3
  412.     
  413.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  414.     move.b    0(a0, d0.w*1), d0
  415.     bra        @drawpixel3
  416.  
  417. @notzero3
  418.     lea.l    intensity_table, a0            ; look up the intensity in the table
  419.     move.l    0(a0, d0.w*4), d0
  420.  
  421.     move.l    #15, d1
  422.     asr.l    d1, d0
  423.     move.l    d0, intensity
  424.  
  425.     move.l    color, a0
  426.     lea        new_color, a1
  427.     lea        old_color, a2
  428.     moveq    #0, d1                        ; Find intensities of color components
  429.     move.w    0(a0), d1
  430.     muls.l    d1, d0
  431.     moveq    #15, d2
  432.     asr.l    d2, d0
  433.     add.w    0(a2), d0
  434.     bcc        @red_ok3
  435.     move.w    #0xFFFF, d0
  436. red_ok3:
  437.     move.w    d0, 0(a1)
  438.     
  439.     move.l    intensity, d0
  440.     move.w    2(a0), d1
  441.     muls.l    d1, d0
  442.     moveq    #15, d2
  443.     asr.l    d2, d0
  444.     add.w    2(a2), d0
  445.     bcc        @green_ok3
  446.     move.w    #0xFFFF, d0
  447. green_ok3:
  448.     move.w    d0, 2(a1)
  449.     
  450.     move.l    intensity, d0
  451.     moveq    #0, d1
  452.     move.w    4(a0), d1
  453.     muls.l    d1, d0
  454.     moveq    #15, d2
  455.     asr.l    d2, d0
  456.     add.w    4(a2), d0
  457.     bcc        @blue_ok3
  458.     move.w    #0xFFFF, d0
  459. blue_ok3:
  460.     move.w    d0, 4(a1)
  461.  
  462.     move.l    a1, -(SP)            ; find index for new_color
  463.     _Color2Index
  464.     
  465. drawpixel3:
  466.     move.b    d0, (pix)
  467.  
  468.     add.l    line_width, pix                ; pix += line_width;
  469.  
  470.     bra        @xloop;
  471.  
  472.     }
  473.  
  474.  
  475. done:;
  476.  
  477. }    //==== DrawAntialiasedLineO1asm() ====\\
  478.  
  479.  
  480.  
  481. void DrawAntialiasedLineO2asm(long x1, long y1, long x2, long y2, RGBColor *color);
  482. void DrawAntialiasedLineO2asm(long x1, long y1, long x2, long y2, RGBColor *color)
  483. {
  484.  
  485.     long             dx, dy;
  486.     register long    d;
  487.     register long    line_width;
  488.     register long    two_dx_invDenom;
  489.     long            invDenom;
  490.     register long    count;
  491.     long             incrE, incrNE, two_v_dx;
  492.     RGBColor         old_color;
  493.     RGBColor         new_color;
  494.     PixMapHandle     pixmap;
  495.     register unsigned char    *pix;
  496.  
  497.     unsigned char    color_table[16];
  498.     RGBColor        table_color;
  499.     long            i, debug;
  500.     Fract            fract_intensity;
  501.     Fixed            intensity;
  502.     
  503.     pixmap = ((CGrafPtr) thePort)->portPixMap;        //  Find address of starting pixel
  504.     line_width = (*pixmap)->rowBytes & 0x7FFF;
  505.     pix = (unsigned char *) (*pixmap)->baseAddr -
  506.                             (*pixmap)->bounds.top*line_width -
  507.                             (*pixmap)->bounds.left +
  508.                             line_width*x1 + y1;
  509.  
  510. asm {
  511.  
  512. //==== create table of frequently used colors (used when drawing on black)
  513.  
  514.     move.l    d3, -(SP)                    ; save d3
  515.     
  516.     move.l    #15, count
  517.  
  518. color_loop:
  519.  
  520.     lea        table_color, a1
  521.     
  522.     lea        intensity_table, a0            ; look up the intensity in the table
  523.     move.l    count, d0
  524.     move.l    d0, debug
  525.     move.l    0(a0, d0.w*4), d3
  526.     move.l    d3, debug
  527.  
  528.     move.l    #15, d1                        ; intensity in d3
  529.     asr.l    d1, d3
  530.  
  531.     move.l    d3, debug
  532.  
  533.     move.l    color, a0                    ; multiply red by intensity
  534.     moveq    #0, d0                        
  535.     move.w    0(a0), d0
  536.     muls.l    d3, d0
  537.     moveq    #15, d2
  538.     asr.l    d2, d0
  539.     move.w    d0, 0(a1)
  540.  
  541.     moveq    #0, d0                        ; multiply green by intensity
  542.     move.w    2(a0), d0
  543.     muls.l    d3, d0
  544.     moveq    #15, d2
  545.     asr.l    d2, d0
  546.     move.w    d0, 2(a1)
  547.  
  548.     moveq    #0, d0                        ; multiply blue by intensity
  549.     move.w    4(a0), d0
  550.     muls.l    d3, d0
  551.     moveq    #15, d2
  552.     asr.l    d2, d0
  553.     move.w    d0, 4(a1)
  554.  
  555.     move.l    a1, -(SP)                    ; find index for this color
  556.     _Color2Index
  557.     
  558.     lea        color_table, a0                ; save this index in the table
  559.     move.b    d0, 0(a0, count)
  560.     
  561.     subq    #1, count
  562.     bpl        @color_loop
  563.     
  564.     move.l    (SP)+, d3                    ; restore d3
  565.  
  566. //==== set up to draw line    
  567.     
  568.     move.l    x2, dx                ; dx = x2 - x1
  569.     move.l    x1, d0
  570.     sub.l    d0, dx
  571.     
  572.     move.l    y2, dy                ; dy = y2 - y1
  573.     move.l    y1, d0
  574.     sub.l    d0, dy
  575.     
  576.     move.l    dy, d                ; d = 2*dy - dx
  577.     add.l    d, d
  578.     sub.l    dx, d
  579.     
  580.     move.l    dy, d0                ; incrE = 2*dy
  581.     add.l    d0, d0
  582.     move.l    d0, incrE
  583.     
  584.     move.l    dy, d0                ; incrNE = 2*(dy-dx)
  585.     sub.l    dx, d0
  586.     add.l    d0, d0
  587.     move.l    d0, incrNE
  588.  
  589.     move.l    #0, two_v_dx;        ; two_v_dx = 0
  590.     
  591.     ; the next section computes 1/(2*sqrt(dx*dx + dy*dy) using integer arithmetic
  592.     
  593.     move.l    dx, d0                ; compute dx*dx + dy*dy
  594.     muls.l    d0, d0
  595.     move.l    dy, d1
  596.     muls.l    d1, d1
  597.     add.l    d1, d0
  598.     
  599.     move.l    #12, d1
  600.     asl.l    d1, d0                ; take the square root
  601.     move.l    d0, -(SP)
  602.     _FracSqrt
  603.  
  604.     move.l    (SP), d0            ; find the denominator
  605.     asr.l    #4, d0
  606.     
  607.     move.l    #0x10000, -(SP)        ; do the division
  608.     move.l    d0, -(SP)
  609.     _FracDiv
  610.  
  611.     move.l    (SP), invDenom
  612.     
  613.     move.l    invDenom, two_dx_invDenom    ; two_dx_invDenom = 2*dx*invDenom
  614.     muls.l    dx, two_dx_invDenom
  615.     add.l    two_dx_invDenom, two_dx_invDenom
  616.  
  617.     move.l    dx, count
  618.     
  619.     bra        @move_done
  620.     
  621. xloop:
  622.  
  623.     sub.l    #1, count            ; loop while count > 0
  624.     bmi        @done
  625.  
  626.     tst.l    d
  627.     bge        @move_northeast
  628.  
  629. move_north:
  630.  
  631.     move.l    d, d0                ; two_v_dx = d + dx
  632.     add.l    dx, d0
  633.     move.l    d0, two_v_dx
  634.     
  635.     add.l    incrE, d            ; d = d + incrE
  636.         
  637.     add.l    line_width, pix        ; y = y + 1
  638.     
  639.     bra        @move_done
  640.     
  641. move_northeast:
  642.  
  643.     move.l    d, d0                ; two_v_dx = d - dx
  644.     sub.l    dx, d0
  645.     move.l    d0, two_v_dx
  646.     
  647.     add.l    incrNE, d            ; d = d + incrE
  648.     
  649.     add.l    line_width, pix        ; y = y + 1
  650.     addq    #1, pix                ; x = x + 1
  651.  
  652. move_done:
  653.  
  654.  
  655. //========== Draw first pixel
  656.     
  657.     moveq    #0, d0                        ; push pixel value
  658.     move.b    (pix), d0
  659.     move.l    d0, -(SP)
  660.     pea        old_color                    ; push address of old_color
  661.     _Index2Color                        ; get previous rgb pixel value
  662.  
  663.     move.l    two_v_dx, d0                ; distance = two_v_dx * invDenom
  664.     muls.l    invDenom, d0
  665.  
  666.     bpl        @positive1                    ; get absolute value of distance
  667.  
  668.     neg.l    d0
  669.  
  670. positive1:
  671.  
  672.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  673.     asr.l    d1, d0
  674.     muls.l    #10, d0
  675.     add.l    #0x8000, d0
  676.     moveq.l    #16, d1
  677.     asr.l    d1, d0
  678.     
  679.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  680.     tst.l    (a0)
  681.     bne        @notzero1
  682.     tst.w    4(a0)
  683.     bne        @notzero1
  684.     
  685.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  686.     move.b    0(a0, d0), d0
  687.     bra        @drawpixel1
  688.  
  689. @notzero1
  690.     
  691.     lea.l    intensity_table, a0            ; look up the intensity in the table
  692.     move.l    0(a0, d0*4), d0
  693.  
  694.     move.l    #15, d1
  695.     asr.l    d1, d0
  696.     move.l    d0, intensity
  697.  
  698.     move.l    color, a0
  699.     lea        new_color, a1
  700.     lea        old_color, a2
  701.     moveq    #0, d1                        ; Find intensities of color components
  702.     move.w    0(a0), d1
  703.     muls.l    d1, d0
  704.     moveq    #15, d2
  705.     asr.l    d2, d0
  706.     add.w    0(a2), d0
  707.     bcc        @red_ok1
  708.     move.w    #0xFFFF, d0
  709. red_ok1:
  710.     move.w    d0, 0(a1)
  711.     
  712.     move.l    intensity, d0
  713.     move.w    2(a0), d1
  714.     muls.l    d1, d0
  715.     moveq    #15, d2
  716.     asr.l    d2, d0
  717.     add.w    2(a2), d0
  718.     bcc        @green_ok1
  719.     move.w    #0xFFFF, d0
  720. green_ok1:
  721.     move.w    d0, 2(a1)
  722.     
  723.     move.l    intensity, d0
  724.     moveq    #0, d1
  725.     move.w    4(a0), d1
  726.     muls.l    d1, d0
  727.     moveq    #15, d2
  728.     asr.l    d2, d0
  729.     add.w    4(a2), d0
  730.     bcc        @blue_ok1
  731.     move.w    #0xFFFF, d0
  732. blue_ok1:
  733.     move.w    d0, 4(a1)
  734.  
  735.     move.l    a1, -(SP)            ; find index for new_color
  736.     _Color2Index
  737.     
  738. drawpixel1:
  739.  
  740.     move.b    d0, (pix)
  741.  
  742.  
  743. //======== Draw the second pixel
  744.  
  745.     addq    #1, pix                        ; pix += 1;
  746.  
  747.     moveq    #0, d0                        ; push pixel value
  748.     move.b    (pix), d0
  749.     move.l    d0, -(SP)
  750.     pea        old_color                    ; push address of old_color
  751.     _Index2Color                        ; get previous rgb pixel value
  752.  
  753.     move.l    two_v_dx, d1                ; distance = two_dx_invDenom - two_v_dx * invDenom
  754.     muls.l    invDenom, d1
  755.     move.l    two_dx_invDenom, d0
  756.     sub.l    d1, d0
  757.  
  758.     bpl        @positive2                    ; get absolute value of distance
  759.  
  760.     neg.l    d0
  761.  
  762. positive2:
  763.  
  764.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  765.     asr.l    d1, d0
  766.     muls.l    #10, d0
  767.     add.l    #0x8000, d0
  768.     moveq.l    #16, d1
  769.     asr.l    d1, d0
  770.     
  771.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  772.     tst.l    (a0)
  773.     bne        @notzero2
  774.     tst.w    4(a0)
  775.     bne        @notzero2
  776.     
  777.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  778.     move.b    0(a0, d0.w*1), d0
  779.     bra        @drawpixel2
  780.  
  781. notzero2:
  782.     lea.l    intensity_table, a0            ; look up the intensity in the table
  783.     move.l    0(a0, d0.w*4), d0
  784.  
  785.     move.l    #15, d1
  786.     asr.l    d1, d0
  787.     move.l    d0, intensity
  788.  
  789.     move.l    color, a0
  790.     lea        new_color, a1
  791.     lea        old_color, a2
  792.     moveq    #0, d1                        ; Find intensities of color components
  793.     move.w    0(a0), d1
  794.     muls.l    d1, d0
  795.     moveq    #15, d2
  796.     asr.l    d2, d0
  797.     add.w    0(a2), d0
  798.     bcc        @red_ok2
  799.     move.w    #0xFFFF, d0
  800. red_ok2:
  801.     move.w    d0, 0(a1)
  802.     
  803.     move.l    intensity, d0
  804.     move.w    2(a0), d1
  805.     muls.l    d1, d0
  806.     moveq    #15, d2
  807.     asr.l    d2, d0
  808.     add.w    2(a2), d0
  809.     bcc        @green_ok2
  810.     move.w    #0xFFFF, d0
  811. green_ok2:
  812.     move.w    d0, 2(a1)
  813.     
  814.     move.l    intensity, d0
  815.     moveq    #0, d1
  816.     move.w    4(a0), d1
  817.     muls.l    d1, d0
  818.     moveq    #15, d2
  819.     asr.l    d2, d0
  820.     add.w    4(a2), d0
  821.     bcc        @blue_ok2
  822.     move.w    #0xFFFF, d0
  823. blue_ok2:
  824.     move.w    d0, 4(a1)
  825.  
  826.     move.l    a1, -(SP)            ; find index for new_color
  827.     _Color2Index
  828.     
  829. drawpixel2:
  830.     move.b    d0, (pix)
  831.  
  832.     subq    #1, pix                        ; pix -= 1;
  833.  
  834.  
  835. //======== Draw the third pixel
  836.  
  837.     subq    #1, pix                        ; pix -= 1;
  838.  
  839.     moveq    #0, d0                        ; push pixel value
  840.     move.b    (pix), d0
  841.     move.l    d0, -(SP)
  842.     pea        old_color                    ; push address of old_color
  843.     _Index2Color                        ; get previous rgb pixel value
  844.  
  845.     move.l    two_v_dx, d0                ; distance = two_dx_invDenom + two_v_dx * invDenom
  846.     muls.l    invDenom, d0
  847.     add.l    two_dx_invDenom, d0
  848.  
  849.     bpl        @positive3                    ; get absolute value of distance
  850.  
  851.     neg.l    d0
  852.  
  853. positive3:
  854.  
  855.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  856.     asr.l    d1, d0
  857.     muls.l    #10, d0
  858.     add.l    #0x8000, d0
  859.     moveq.l    #16, d1
  860.     asr.l    d1, d0
  861.     
  862.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  863.     tst.l    (a0)
  864.     bne        @notzero3
  865.     tst.w    4(a0)
  866.     bne        @notzero3
  867.     
  868.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  869.     move.b    0(a0, d0.w*1), d0
  870.     bra        @drawpixel3
  871.  
  872. @notzero3
  873.     lea.l    intensity_table, a0            ; look up the intensity in the table
  874.     move.l    0(a0, d0.w*4), d0
  875.  
  876.     move.l    #15, d1
  877.     asr.l    d1, d0
  878.     move.l    d0, intensity
  879.  
  880.     move.l    color, a0
  881.     lea        new_color, a1
  882.     lea        old_color, a2
  883.     moveq    #0, d1                        ; Find intensities of color components
  884.     move.w    0(a0), d1
  885.     muls.l    d1, d0
  886.     moveq    #15, d2
  887.     asr.l    d2, d0
  888.     add.w    0(a2), d0
  889.     bcc        @red_ok3
  890.     move.w    #0xFFFF, d0
  891. red_ok3:
  892.     move.w    d0, 0(a1)
  893.     
  894.     move.l    intensity, d0
  895.     move.w    2(a0), d1
  896.     muls.l    d1, d0
  897.     moveq    #15, d2
  898.     asr.l    d2, d0
  899.     add.w    2(a2), d0
  900.     bcc        @green_ok3
  901.     move.w    #0xFFFF, d0
  902. green_ok3:
  903.     move.w    d0, 2(a1)
  904.     
  905.     move.l    intensity, d0
  906.     moveq    #0, d1
  907.     move.w    4(a0), d1
  908.     muls.l    d1, d0
  909.     moveq    #15, d2
  910.     asr.l    d2, d0
  911.     add.w    4(a2), d0
  912.     bcc        @blue_ok3
  913.     move.w    #0xFFFF, d0
  914. blue_ok3:
  915.     move.w    d0, 4(a1)
  916.  
  917.     move.l    a1, -(SP)            ; find index for new_color
  918.     _Color2Index
  919.     
  920. drawpixel3:
  921.     move.b    d0, (pix)
  922.  
  923.     addq    #1, pix                ; pix += 1
  924.  
  925.     bra        @xloop;
  926.  
  927.     }
  928.  
  929.  
  930. done:;
  931.  
  932. }    //==== DrawAntialiasedLineO2asm() ====\\
  933.  
  934.  
  935.  
  936. void DrawAntialiasedLineO3asm(long x1, long y1, long x2, long y2, RGBColor *color);
  937. void DrawAntialiasedLineO3asm(long x1, long y1, long x2, long y2, RGBColor *color)
  938. {
  939.  
  940.     long             dx, dy;
  941.     register long    d;
  942.     register long    line_width;
  943.     register long    two_dx_invDenom;
  944.     long            invDenom;
  945.     register long    count;
  946.     long             incrE, incrNE, two_v_dx;
  947.     RGBColor         old_color;
  948.     RGBColor         new_color;
  949.     PixMapHandle     pixmap;
  950.     register unsigned char    *pix;
  951.  
  952.     unsigned char    color_table[16];
  953.     RGBColor        table_color;
  954.     long            i, debug;
  955.     Fract            fract_intensity;
  956.     Fixed            intensity;
  957.     
  958.     pixmap = ((CGrafPtr) thePort)->portPixMap;        //  Find address of starting pixel
  959.     line_width = (*pixmap)->rowBytes & 0x7FFF;
  960.     pix = (unsigned char *) (*pixmap)->baseAddr -
  961.                             (*pixmap)->bounds.top*line_width -
  962.                             (*pixmap)->bounds.left -
  963.                             line_width*x1 + y1;
  964.  
  965. asm {
  966.  
  967. //==== create table of frequently used colors (used when drawing on black)
  968.  
  969.     move.l    d3, -(SP)                    ; save d3
  970.     
  971.     move.l    #15, count
  972.  
  973. color_loop:
  974.  
  975.     lea        table_color, a1
  976.     
  977.     lea        intensity_table, a0            ; look up the intensity in the table
  978.     move.l    count, d0
  979.     move.l    d0, debug
  980.     move.l    0(a0, d0.w*4), d3
  981.     move.l    d3, debug
  982.  
  983.     move.l    #15, d1                        ; intensity in d3
  984.     asr.l    d1, d3
  985.  
  986.     move.l    d3, debug
  987.  
  988.     move.l    color, a0                    ; multiply red by intensity
  989.     moveq    #0, d0                        
  990.     move.w    0(a0), d0
  991.     muls.l    d3, d0
  992.     moveq    #15, d2
  993.     asr.l    d2, d0
  994.     move.w    d0, 0(a1)
  995.  
  996.     moveq    #0, d0                        ; multiply green by intensity
  997.     move.w    2(a0), d0
  998.     muls.l    d3, d0
  999.     moveq    #15, d2
  1000.     asr.l    d2, d0
  1001.     move.w    d0, 2(a1)
  1002.  
  1003.     moveq    #0, d0                        ; multiply blue by intensity
  1004.     move.w    4(a0), d0
  1005.     muls.l    d3, d0
  1006.     moveq    #15, d2
  1007.     asr.l    d2, d0
  1008.     move.w    d0, 4(a1)
  1009.  
  1010.     move.l    a1, -(SP)                    ; find index for this color
  1011.     _Color2Index
  1012.     
  1013.     lea        color_table, a0                ; save this index in the table
  1014.     move.b    d0, 0(a0, count)
  1015.     
  1016.     subq    #1, count
  1017.     bpl        @color_loop
  1018.     
  1019.     move.l    (SP)+, d3                    ; restore d3
  1020.  
  1021. //==== set up to draw line    
  1022.     
  1023.     move.l    x2, dx                ; dx = x2 - x1
  1024.     move.l    x1, d0
  1025.     sub.l    d0, dx
  1026.     
  1027.     move.l    y2, dy                ; dy = y2 - y1
  1028.     move.l    y1, d0
  1029.     sub.l    d0, dy
  1030.     
  1031.     move.l    dy, d                ; d = 2*dy - dx
  1032.     add.l    d, d
  1033.     sub.l    dx, d
  1034.     
  1035.     move.l    dy, d0                ; incrE = 2*dy
  1036.     add.l    d0, d0
  1037.     move.l    d0, incrE
  1038.     
  1039.     move.l    dy, d0                ; incrNE = 2*(dy-dx)
  1040.     sub.l    dx, d0
  1041.     add.l    d0, d0
  1042.     move.l    d0, incrNE
  1043.  
  1044.     move.l    #0, two_v_dx;        ; two_v_dx = 0
  1045.     
  1046.     ; the next section computes 1/(2*sqrt(dx*dx + dy*dy) using integer arithmetic
  1047.     
  1048.     move.l    dx, d0                ; compute dx*dx + dy*dy
  1049.     muls.l    d0, d0
  1050.     move.l    dy, d1
  1051.     muls.l    d1, d1
  1052.     add.l    d1, d0
  1053.     
  1054.     move.l    #12, d1
  1055.     asl.l    d1, d0                ; take the square root
  1056.     move.l    d0, -(SP)
  1057.     _FracSqrt
  1058.  
  1059.     move.l    (SP), d0            ; find the denominator
  1060.     asr.l    #4, d0
  1061.     
  1062.     move.l    #0x10000, -(SP)        ; do the division
  1063.     move.l    d0, -(SP)
  1064.     _FracDiv
  1065.  
  1066.     move.l    (SP), invDenom
  1067.     
  1068.     move.l    invDenom, two_dx_invDenom    ; two_dx_invDenom = 2*dx*invDenom
  1069.     muls.l    dx, two_dx_invDenom
  1070.     add.l    two_dx_invDenom, two_dx_invDenom
  1071.  
  1072.     move.l    dx, count
  1073.     
  1074.     bra        @move_done
  1075.     
  1076. xloop:
  1077.  
  1078.     sub.l    #1, count            ; loop while count > 0
  1079.     bmi        @done
  1080.  
  1081.     tst.l    d
  1082.     bge        @move_northwest
  1083.  
  1084. move_west:
  1085.  
  1086.     move.l    d, d0                ; two_v_dx = d + dx
  1087.     add.l    dx, d0
  1088.     move.l    d0, two_v_dx
  1089.     
  1090.     add.l    incrE, d            ; d = d + incrE
  1091.         
  1092.     sub.l    line_width, pix        ; y = y + 1
  1093.     
  1094.     bra        @move_done
  1095.     
  1096. move_northwest:
  1097.  
  1098.     move.l    d, d0                ; two_v_dx = d - dx
  1099.     sub.l    dx, d0
  1100.     move.l    d0, two_v_dx
  1101.     
  1102.     add.l    incrNE, d            ; d = d + incrE
  1103.     
  1104.     sub.l    line_width, pix        ; y = y + 1
  1105.     addq    #1, pix                ; x = x - 1
  1106.  
  1107. move_done:
  1108.  
  1109.  
  1110. //========== Draw first pixel
  1111.     
  1112.     moveq    #0, d0                        ; push pixel value
  1113.     move.b    (pix), d0
  1114.     move.l    d0, -(SP)
  1115.     pea        old_color                    ; push address of old_color
  1116.     _Index2Color                        ; get previous rgb pixel value
  1117.  
  1118.     move.l    two_v_dx, d0                ; distance = two_v_dx * invDenom
  1119.     muls.l    invDenom, d0
  1120.  
  1121.     bpl        @positive1                    ; get absolute value of distance
  1122.  
  1123.     neg.l    d0
  1124.  
  1125. positive1:
  1126.  
  1127.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  1128.     asr.l    d1, d0
  1129.     muls.l    #10, d0
  1130.     add.l    #0x8000, d0
  1131.     moveq.l    #16, d1
  1132.     asr.l    d1, d0
  1133.     
  1134.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  1135.     tst.l    (a0)
  1136.     bne        @notzero1
  1137.     tst.w    4(a0)
  1138.     bne        @notzero1
  1139.     
  1140.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  1141.     move.b    0(a0, d0), d0
  1142.     bra        @drawpixel1
  1143.  
  1144. @notzero1
  1145.     
  1146.     lea.l    intensity_table, a0            ; look up the intensity in the table
  1147.     move.l    0(a0, d0*4), d0
  1148.  
  1149.     move.l    #15, d1
  1150.     asr.l    d1, d0
  1151.     move.l    d0, intensity
  1152.  
  1153.     move.l    color, a0
  1154.     lea        new_color, a1
  1155.     lea        old_color, a2
  1156.     moveq    #0, d1                        ; Find intensities of color components
  1157.     move.w    0(a0), d1
  1158.     muls.l    d1, d0
  1159.     moveq    #15, d2
  1160.     asr.l    d2, d0
  1161.     add.w    0(a2), d0
  1162.     bcc        @red_ok1
  1163.     move.w    #0xFFFF, d0
  1164. red_ok1:
  1165.     move.w    d0, 0(a1)
  1166.     
  1167.     move.l    intensity, d0
  1168.     move.w    2(a0), d1
  1169.     muls.l    d1, d0
  1170.     moveq    #15, d2
  1171.     asr.l    d2, d0
  1172.     add.w    2(a2), d0
  1173.     bcc        @green_ok1
  1174.     move.w    #0xFFFF, d0
  1175. green_ok1:
  1176.     move.w    d0, 2(a1)
  1177.     
  1178.     move.l    intensity, d0
  1179.     moveq    #0, d1
  1180.     move.w    4(a0), d1
  1181.     muls.l    d1, d0
  1182.     moveq    #15, d2
  1183.     asr.l    d2, d0
  1184.     add.w    4(a2), d0
  1185.     bcc        @blue_ok1
  1186.     move.w    #0xFFFF, d0
  1187. blue_ok1:
  1188.     move.w    d0, 4(a1)
  1189.  
  1190.     move.l    a1, -(SP)            ; find index for new_color
  1191.     _Color2Index
  1192.     
  1193. drawpixel1:
  1194.  
  1195.     move.b    d0, (pix)
  1196.  
  1197.  
  1198. //======== Draw the second pixel
  1199.  
  1200.     addq    #1, pix                        ; pix += 1;
  1201.  
  1202.     moveq    #0, d0                        ; push pixel value
  1203.     move.b    (pix), d0
  1204.     move.l    d0, -(SP)
  1205.     pea        old_color                    ; push address of old_color
  1206.     _Index2Color                        ; get previous rgb pixel value
  1207.  
  1208.     move.l    two_v_dx, d1                ; distance = two_dx_invDenom - two_v_dx * invDenom
  1209.     muls.l    invDenom, d1
  1210.     move.l    two_dx_invDenom, d0
  1211.     sub.l    d1, d0
  1212.  
  1213.     bpl        @positive2                    ; get absolute value of distance
  1214.  
  1215.     neg.l    d0
  1216.  
  1217. positive2:
  1218.  
  1219.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  1220.     asr.l    d1, d0
  1221.     muls.l    #10, d0
  1222.     add.l    #0x8000, d0
  1223.     moveq.l    #16, d1
  1224.     asr.l    d1, d0
  1225.     
  1226.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  1227.     tst.l    (a0)
  1228.     bne        @notzero2
  1229.     tst.w    4(a0)
  1230.     bne        @notzero2
  1231.     
  1232.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  1233.     move.b    0(a0, d0.w*1), d0
  1234.     bra        @drawpixel2
  1235.  
  1236. notzero2:
  1237.     lea.l    intensity_table, a0            ; look up the intensity in the table
  1238.     move.l    0(a0, d0.w*4), d0
  1239.  
  1240.     move.l    #15, d1
  1241.     asr.l    d1, d0
  1242.     move.l    d0, intensity
  1243.  
  1244.     move.l    color, a0
  1245.     lea        new_color, a1
  1246.     lea        old_color, a2
  1247.     moveq    #0, d1                        ; Find intensities of color components
  1248.     move.w    0(a0), d1
  1249.     muls.l    d1, d0
  1250.     moveq    #15, d2
  1251.     asr.l    d2, d0
  1252.     add.w    0(a2), d0
  1253.     bcc        @red_ok2
  1254.     move.w    #0xFFFF, d0
  1255. red_ok2:
  1256.     move.w    d0, 0(a1)
  1257.     
  1258.     move.l    intensity, d0
  1259.     move.w    2(a0), d1
  1260.     muls.l    d1, d0
  1261.     moveq    #15, d2
  1262.     asr.l    d2, d0
  1263.     add.w    2(a2), d0
  1264.     bcc        @green_ok2
  1265.     move.w    #0xFFFF, d0
  1266. green_ok2:
  1267.     move.w    d0, 2(a1)
  1268.     
  1269.     move.l    intensity, d0
  1270.     moveq    #0, d1
  1271.     move.w    4(a0), d1
  1272.     muls.l    d1, d0
  1273.     moveq    #15, d2
  1274.     asr.l    d2, d0
  1275.     add.w    4(a2), d0
  1276.     bcc        @blue_ok2
  1277.     move.w    #0xFFFF, d0
  1278. blue_ok2:
  1279.     move.w    d0, 4(a1)
  1280.  
  1281.     move.l    a1, -(SP)            ; find index for new_color
  1282.     _Color2Index
  1283.     
  1284. drawpixel2:
  1285.     move.b    d0, (pix)
  1286.  
  1287.     subq    #1, pix                        ; pix -= 1;
  1288.  
  1289.  
  1290. //======== Draw the third pixel
  1291.  
  1292.     subq    #1, pix                        ; pix -= 1;
  1293.  
  1294.     moveq    #0, d0                        ; push pixel value
  1295.     move.b    (pix), d0
  1296.     move.l    d0, -(SP)
  1297.     pea        old_color                    ; push address of old_color
  1298.     _Index2Color                        ; get previous rgb pixel value
  1299.  
  1300.     move.l    two_v_dx, d0                ; distance = two_dx_invDenom + two_v_dx * invDenom
  1301.     muls.l    invDenom, d0
  1302.     add.l    two_dx_invDenom, d0
  1303.  
  1304.     bpl        @positive3                    ; get absolute value of distance
  1305.  
  1306.     neg.l    d0
  1307.  
  1308. positive3:
  1309.  
  1310.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  1311.     asr.l    d1, d0
  1312.     muls.l    #10, d0
  1313.     add.l    #0x8000, d0
  1314.     moveq.l    #16, d1
  1315.     asr.l    d1, d0
  1316.     
  1317.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  1318.     tst.l    (a0)
  1319.     bne        @notzero3
  1320.     tst.w    4(a0)
  1321.     bne        @notzero3
  1322.     
  1323.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  1324.     move.b    0(a0, d0.w*1), d0
  1325.     bra        @drawpixel3
  1326.  
  1327. @notzero3
  1328.     lea.l    intensity_table, a0            ; look up the intensity in the table
  1329.     move.l    0(a0, d0.w*4), d0
  1330.  
  1331.     move.l    #15, d1
  1332.     asr.l    d1, d0
  1333.     move.l    d0, intensity
  1334.  
  1335.     move.l    color, a0
  1336.     lea        new_color, a1
  1337.     lea        old_color, a2
  1338.     moveq    #0, d1                        ; Find intensities of color components
  1339.     move.w    0(a0), d1
  1340.     muls.l    d1, d0
  1341.     moveq    #15, d2
  1342.     asr.l    d2, d0
  1343.     add.w    0(a2), d0
  1344.     bcc        @red_ok3
  1345.     move.w    #0xFFFF, d0
  1346. red_ok3:
  1347.     move.w    d0, 0(a1)
  1348.     
  1349.     move.l    intensity, d0
  1350.     move.w    2(a0), d1
  1351.     muls.l    d1, d0
  1352.     moveq    #15, d2
  1353.     asr.l    d2, d0
  1354.     add.w    2(a2), d0
  1355.     bcc        @green_ok3
  1356.     move.w    #0xFFFF, d0
  1357. green_ok3:
  1358.     move.w    d0, 2(a1)
  1359.     
  1360.     move.l    intensity, d0
  1361.     moveq    #0, d1
  1362.     move.w    4(a0), d1
  1363.     muls.l    d1, d0
  1364.     moveq    #15, d2
  1365.     asr.l    d2, d0
  1366.     add.w    4(a2), d0
  1367.     bcc        @blue_ok3
  1368.     move.w    #0xFFFF, d0
  1369. blue_ok3:
  1370.     move.w    d0, 4(a1)
  1371.  
  1372.     move.l    a1, -(SP)            ; find index for new_color
  1373.     _Color2Index
  1374.     
  1375. drawpixel3:
  1376.     move.b    d0, (pix)
  1377.  
  1378.     addq    #1, pix                ; pix += 1
  1379.  
  1380.     bra        @xloop;
  1381.  
  1382.     }
  1383.  
  1384.  
  1385. done:;
  1386.  
  1387. }    //==== DrawAntialiasedLineO3asm() ====\\
  1388.  
  1389.  
  1390.  
  1391. void DrawAntialiasedLineO4asm(long x1, long y1, long x2, long y2, RGBColor *color);
  1392. void DrawAntialiasedLineO4asm(long x1, long y1, long x2, long y2, RGBColor *color)
  1393. {
  1394.  
  1395.     long             dx, dy;
  1396.     register long    d;
  1397.     register long    line_width;
  1398.     register long    two_dx_invDenom;
  1399.     long            invDenom;
  1400.     register long    count;
  1401.     long             incrE, incrNE, two_v_dx;
  1402.     RGBColor         old_color;
  1403.     RGBColor         new_color;
  1404.     PixMapHandle     pixmap;
  1405.     register unsigned char    *pix;
  1406.  
  1407.     unsigned char    color_table[16];
  1408.     RGBColor        table_color;
  1409.     long            i, debug;
  1410.     Fract            fract_intensity;
  1411.     Fixed            intensity;
  1412.     
  1413.     pixmap = ((CGrafPtr) thePort)->portPixMap;        //  Find address of starting pixel
  1414.     line_width = (*pixmap)->rowBytes & 0x7FFF;
  1415.     pix = (unsigned char *) (*pixmap)->baseAddr -
  1416.                             (*pixmap)->bounds.top*line_width -
  1417.                             (*pixmap)->bounds.left -
  1418.                             line_width*y1 + x1;
  1419.  
  1420. asm {
  1421.  
  1422. //==== create table of frequently used colors (used when drawing on black    
  1423.  
  1424.     move.l    d3, -(SP)                    ; save d3
  1425.     
  1426.     move.l    #15, count
  1427.  
  1428. color_loop:
  1429.  
  1430.     lea        table_color, a1
  1431.     
  1432.     lea        intensity_table, a0            ; look up the intensity in the table
  1433.     move.l    count, d0
  1434.     move.l    d0, debug
  1435.     move.l    0(a0, d0.w*4), d3
  1436.     move.l    d3, debug
  1437.  
  1438.     move.l    #15, d1                        ; intensity in d3
  1439.     asr.l    d1, d3
  1440.  
  1441.     move.l    d3, debug
  1442.  
  1443.     move.l    color, a0                    ; multiply red by intensity
  1444.     moveq    #0, d0                        
  1445.     move.w    0(a0), d0
  1446.     muls.l    d3, d0
  1447.     moveq    #15, d2
  1448.     asr.l    d2, d0
  1449.     move.w    d0, 0(a1)
  1450.  
  1451.     moveq    #0, d0                        ; multiply green by intensity
  1452.     move.w    2(a0), d0
  1453.     muls.l    d3, d0
  1454.     moveq    #15, d2
  1455.     asr.l    d2, d0
  1456.     move.w    d0, 2(a1)
  1457.  
  1458.     moveq    #0, d0                        ; multiply blue by intensity
  1459.     move.w    4(a0), d0
  1460.     muls.l    d3, d0
  1461.     moveq    #15, d2
  1462.     asr.l    d2, d0
  1463.     move.w    d0, 4(a1)
  1464.  
  1465.     move.l    a1, -(SP)                    ; find index for this color
  1466.     _Color2Index
  1467.     
  1468.     lea        color_table, a0                ; save this index in the table
  1469.     move.b    d0, 0(a0, count)
  1470.     
  1471.     subq    #1, count
  1472.     bpl        @color_loop
  1473.     
  1474.     move.l    (SP)+, d3                    ; restore d3
  1475.  
  1476. //==== set up to draw line    
  1477.     
  1478.     move.l    x2, dx                ; dx = x2 - x1
  1479.     move.l    x1, d0
  1480.     sub.l    d0, dx
  1481.     
  1482.     move.l    y2, dy                ; dy = y2 - y1
  1483.     move.l    y1, d0
  1484.     sub.l    d0, dy
  1485.     
  1486.     move.l    dy, d                ; d = 2*dy - dx
  1487.     add.l    d, d
  1488.     sub.l    dx, d
  1489.     
  1490.     move.l    dy, d0                ; incrE = 2*dy
  1491.     add.l    d0, d0
  1492.     move.l    d0, incrE
  1493.     
  1494.     move.l    dy, d0                ; incrNE = 2*(dy-dx)
  1495.     sub.l    dx, d0
  1496.     add.l    d0, d0
  1497.     move.l    d0, incrNE
  1498.  
  1499.     move.l    #0, two_v_dx;        ; two_v_dx = 0
  1500.     
  1501.     ; the next section computes 1/(2*sqrt(dx*dx + dy*dy) using integer arithmetic
  1502.     
  1503.     move.l    dx, d0                ; compute dx*dx + dy*dy
  1504.     muls.l    d0, d0
  1505.     move.l    dy, d1
  1506.     muls.l    d1, d1
  1507.     add.l    d1, d0
  1508.     
  1509.     move.l    #12, d1
  1510.     asl.l    d1, d0                ; take the square root
  1511.     move.l    d0, -(SP)
  1512.     _FracSqrt
  1513.  
  1514.     move.l    (SP), d0            ; find the denominator
  1515.     asr.l    #4, d0
  1516.     
  1517.     move.l    #0x10000, -(SP)        ; do the division
  1518.     move.l    d0, -(SP)
  1519.     _FracDiv
  1520.  
  1521.     move.l    (SP), invDenom
  1522.     
  1523.     move.l    invDenom, two_dx_invDenom    ; two_dx_invDenom = 2*dx*invDenom
  1524.     muls.l    dx, two_dx_invDenom
  1525.     add.l    two_dx_invDenom, two_dx_invDenom
  1526.  
  1527.     move.l    dx, count
  1528.     
  1529.     bra        @move_done
  1530.     
  1531. xloop:
  1532.  
  1533.     sub.l    #1, count            ; loop while count > 0
  1534.     bmi        @done
  1535.  
  1536.     tst.l    d
  1537.     bge        @move_northeast
  1538.  
  1539. move_east:
  1540.  
  1541.     move.l    d, d0                ; two_v_dx = d + dx
  1542.     add.l    dx, d0
  1543.     move.l    d0, two_v_dx
  1544.     
  1545.     add.l    incrE, d            ; d = d + incrE
  1546.         
  1547.     addq.l    #1, pix                ; x = x + 1
  1548.     
  1549.     bra        @move_done
  1550.     
  1551. move_northeast:
  1552.  
  1553.     move.l    d, d0                ; two_v_dx = d - dx
  1554.     sub.l    dx, d0
  1555.     move.l    d0, two_v_dx
  1556.     
  1557.     add.l    incrNE, d            ; d = d + incrE
  1558.     
  1559.     sub.l    line_width, pix        ; y = y + 1
  1560.     addq.l    #1, pix                ; x = x + 1
  1561.     
  1562. move_done:
  1563.  
  1564.  
  1565. //========== Draw first pixel
  1566.     
  1567.     moveq    #0, d0                        ; push pixel value
  1568.     move.b    (pix), d0
  1569.     move.l    d0, -(SP)
  1570.     pea        old_color                    ; push address of old_color
  1571.     _Index2Color                        ; get previous rgb pixel value
  1572.  
  1573.     move.l    two_v_dx, d0                ; distance = two_v_dx * invDenom
  1574.     muls.l    invDenom, d0
  1575.  
  1576.     bpl        @positive1                    ; get absolute value of distance
  1577.  
  1578.     neg.l    d0
  1579.  
  1580. positive1:
  1581.  
  1582.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  1583.     asr.l    d1, d0
  1584.     muls.l    #10, d0
  1585.     add.l    #0x8000, d0
  1586.     moveq.l    #16, d1
  1587.     asr.l    d1, d0
  1588.     
  1589.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  1590.     tst.l    (a0)
  1591.     bne        @notzero1
  1592.     tst.w    4(a0)
  1593.     bne        @notzero1
  1594.     
  1595.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  1596.     move.b    0(a0, d0), d0
  1597.     bra        @drawpixel1
  1598.  
  1599. @notzero1
  1600.     
  1601.     lea.l    intensity_table, a0            ; look up the intensity in the table
  1602.     move.l    0(a0, d0*4), d0
  1603.  
  1604.     move.l    #15, d1
  1605.     asr.l    d1, d0
  1606.     move.l    d0, intensity
  1607.  
  1608.     move.l    color, a0
  1609.     lea        new_color, a1
  1610.     lea        old_color, a2
  1611.     moveq    #0, d1                        ; Find intensities of color components
  1612.     move.w    0(a0), d1
  1613.     muls.l    d1, d0
  1614.     moveq    #15, d2
  1615.     asr.l    d2, d0
  1616.     add.w    0(a2), d0
  1617.     bcc        @red_ok1
  1618.     move.w    #0xFFFF, d0
  1619. red_ok1:
  1620.     move.w    d0, 0(a1)
  1621.     
  1622.     move.l    intensity, d0
  1623.     move.w    2(a0), d1
  1624.     muls.l    d1, d0
  1625.     moveq    #15, d2
  1626.     asr.l    d2, d0
  1627.     add.w    2(a2), d0
  1628.     bcc        @green_ok1
  1629.     move.w    #0xFFFF, d0
  1630. green_ok1:
  1631.     move.w    d0, 2(a1)
  1632.     
  1633.     move.l    intensity, d0
  1634.     moveq    #0, d1
  1635.     move.w    4(a0), d1
  1636.     muls.l    d1, d0
  1637.     moveq    #15, d2
  1638.     asr.l    d2, d0
  1639.     add.w    4(a2), d0
  1640.     bcc        @blue_ok1
  1641.     move.w    #0xFFFF, d0
  1642. blue_ok1:
  1643.     move.w    d0, 4(a1)
  1644.  
  1645.     move.l    a1, -(SP)            ; find index for new_color
  1646.     _Color2Index
  1647.     
  1648. drawpixel1:
  1649.  
  1650.     move.b    d0, (pix)
  1651.  
  1652.  
  1653. //======== Draw the second pixel
  1654.  
  1655.     sub.l    line_width, pix                ; pix -= line_width;
  1656.  
  1657.     moveq    #0, d0                        ; push pixel value
  1658.     move.b    (pix), d0
  1659.     move.l    d0, -(SP)
  1660.     pea        old_color                    ; push address of old_color
  1661.     _Index2Color                        ; get previous rgb pixel value
  1662.  
  1663.     move.l    two_v_dx, d1                ; distance = two_dx_invDenom - two_v_dx * invDenom
  1664.     muls.l    invDenom, d1
  1665.     move.l    two_dx_invDenom, d0
  1666.     sub.l    d1, d0
  1667.  
  1668.     bpl        @positive2                    ; get absolute value of distance
  1669.  
  1670.     neg.l    d0
  1671.  
  1672. positive2:
  1673.  
  1674.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  1675.     asr.l    d1, d0
  1676.     muls.l    #10, d0
  1677.     add.l    #0x8000, d0
  1678.     moveq.l    #16, d1
  1679.     asr.l    d1, d0
  1680.     
  1681.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  1682.     tst.l    (a0)
  1683.     bne        @notzero2
  1684.     tst.w    4(a0)
  1685.     bne        @notzero2
  1686.     
  1687.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  1688.     move.b    0(a0, d0.w*1), d0
  1689.     bra        @drawpixel2
  1690.  
  1691. notzero2:
  1692.     lea.l    intensity_table, a0            ; look up the intensity in the table
  1693.     move.l    0(a0, d0.w*4), d0
  1694.  
  1695.     move.l    #15, d1
  1696.     asr.l    d1, d0
  1697.     move.l    d0, intensity
  1698.  
  1699.     move.l    color, a0
  1700.     lea        new_color, a1
  1701.     lea        old_color, a2
  1702.     moveq    #0, d1                        ; Find intensities of color components
  1703.     move.w    0(a0), d1
  1704.     muls.l    d1, d0
  1705.     moveq    #15, d2
  1706.     asr.l    d2, d0
  1707.     add.w    0(a2), d0
  1708.     bcc        @red_ok2
  1709.     move.w    #0xFFFF, d0
  1710. red_ok2:
  1711.     move.w    d0, 0(a1)
  1712.     
  1713.     move.l    intensity, d0
  1714.     move.w    2(a0), d1
  1715.     muls.l    d1, d0
  1716.     moveq    #15, d2
  1717.     asr.l    d2, d0
  1718.     add.w    2(a2), d0
  1719.     bcc        @green_ok2
  1720.     move.w    #0xFFFF, d0
  1721. green_ok2:
  1722.     move.w    d0, 2(a1)
  1723.     
  1724.     move.l    intensity, d0
  1725.     moveq    #0, d1
  1726.     move.w    4(a0), d1
  1727.     muls.l    d1, d0
  1728.     moveq    #15, d2
  1729.     asr.l    d2, d0
  1730.     add.w    4(a2), d0
  1731.     bcc        @blue_ok2
  1732.     move.w    #0xFFFF, d0
  1733. blue_ok2:
  1734.     move.w    d0, 4(a1)
  1735.  
  1736.     move.l    a1, -(SP)            ; find index for new_color
  1737.     _Color2Index
  1738.     
  1739. drawpixel2:
  1740.     move.b    d0, (pix)
  1741.  
  1742.     add.l    line_width, pix                ; pix += line_width
  1743.  
  1744.  
  1745. //======== Draw the third pixel
  1746.  
  1747.     add.l    line_width, pix                ; pix += line_width
  1748.  
  1749.     moveq    #0, d0                        ; push pixel value
  1750.     move.b    (pix), d0
  1751.     move.l    d0, -(SP)
  1752.     pea        old_color                    ; push address of old_color
  1753.     _Index2Color                        ; get previous rgb pixel value
  1754.  
  1755.     move.l    two_v_dx, d0                ; distance = two_dx_invDenom + two_v_dx * invDenom
  1756.     muls.l    invDenom, d0
  1757.     add.l    two_dx_invDenom, d0
  1758.  
  1759.     bpl        @positive3                    ; get absolute value of distance
  1760.  
  1761.     neg.l    d0
  1762.  
  1763. positive3:
  1764.  
  1765.     moveq.l    #14, d1                        ; index = (((abs_distance / 0x4000) * 10) + 0x8000) >> 16
  1766.     asr.l    d1, d0
  1767.     muls.l    #10, d0
  1768.     add.l    #0x8000, d0
  1769.     moveq.l    #16, d1
  1770.     asr.l    d1, d0
  1771.     
  1772.     lea        old_color, a0                ; check if the old color was 0, 0, 0
  1773.     tst.l    (a0)
  1774.     bne        @notzero3
  1775.     tst.w    4(a0)
  1776.     bne        @notzero3
  1777.     
  1778.     lea        color_table, a0                ; if all 0's, we can get the pixel value from the table
  1779.     move.b    0(a0, d0.w*1), d0
  1780.     bra        @drawpixel3
  1781.  
  1782. @notzero3
  1783.     lea.l    intensity_table, a0            ; look up the intensity in the table
  1784.     move.l    0(a0, d0.w*4), d0
  1785.  
  1786.     move.l    #15, d1
  1787.     asr.l    d1, d0
  1788.     move.l    d0, intensity
  1789.  
  1790.     move.l    color, a0
  1791.     lea        new_color, a1
  1792.     lea        old_color, a2
  1793.     moveq    #0, d1                        ; Find intensities of color components
  1794.     move.w    0(a0), d1
  1795.     muls.l    d1, d0
  1796.     moveq    #15, d2
  1797.     asr.l    d2, d0
  1798.     add.w    0(a2), d0
  1799.     bcc        @red_ok3
  1800.     move.w    #0xFFFF, d0
  1801. red_ok3:
  1802.     move.w    d0, 0(a1)
  1803.     
  1804.     move.l    intensity, d0
  1805.     move.w    2(a0), d1
  1806.     muls.l    d1, d0
  1807.     moveq    #15, d2
  1808.     asr.l    d2, d0
  1809.     add.w    2(a2), d0
  1810.     bcc        @green_ok3
  1811.     move.w    #0xFFFF, d0
  1812. green_ok3:
  1813.     move.w    d0, 2(a1)
  1814.     
  1815.     move.l    intensity, d0
  1816.     moveq    #0, d1
  1817.     move.w    4(a0), d1
  1818.     muls.l    d1, d0
  1819.     moveq    #15, d2
  1820.     asr.l    d2, d0
  1821.     add.w    4(a2), d0
  1822.     bcc        @blue_ok3
  1823.     move.w    #0xFFFF, d0
  1824. blue_ok3:
  1825.     move.w    d0, 4(a1)
  1826.  
  1827.     move.l    a1, -(SP)            ; find index for new_color
  1828.     _Color2Index
  1829.     
  1830. drawpixel3:
  1831.     move.b    d0, (pix)
  1832.  
  1833.     sub.l    line_width, pix                ; pix -= line_width
  1834.  
  1835.     bra        @xloop;
  1836.  
  1837.     }
  1838.  
  1839.  
  1840. done:;
  1841.  
  1842. }    //==== DrawAntialiasedLineO4asm() ====\\